/**
 * @Author:周邱艳
 * @Date:2020/6/30
 * @Description:这是阶段涨幅
 */
import React,{Component} from "react";
import { List } from 'antd-mobile';
import axios from "axios";

const Item = List.Item;


export default class StageGain extends Component{
    constructor(props) {
        super(props);
        this.getCategorys()
        this.state={
            combinationYields:[],//总表
        }
        //数据绑定
        this.getCategorys=this.getCategorys.bind(this)
    }

    getCategorys = () => {
        //数据请求
        axios({
            method:"GET",
            url:"http://39.101.141.248:9527/combinationYield/combinationYieldByCombinationId",
            params:{comBaseId:2}//params:{comBaseId:this.props.portfolioId}
        }).then(
            (res) => {
                //状态码判断
                if(res.data.code===200){
                    console.log(res.data.combinationYields)
                    /*for (let i=0;i<res.data.combinationYields.length;i++){
                        if(res.data.combinationYields[i]["comName"]==="原组合"){

                            var dataStatic=res.data.combinationYields[i]["newComIncome"]//数据
                            console.log(dataStatic)
                            var datchildren=res.data.combinationYields[i]["newProTradeDate"]//横坐标
                            console.log(datchildren)
                            const newArr = dataStatic.reduce((res,item)=>{
                                res.push({dataStatic1:item})
                                return res;
                            },[])
                            console.log(newArr)
                            const newArr2 = datchildren.reduce((res,item)=>{
                                res.push({datchildren1:item})
                                return res;
                            },[])
                            console.log(newArr2)
                            //得到总数据新表
                            //dat.push({dataStatic,datchildren})
                            //console.log(dat)
                            var arr=[]
                            for(var j=0;j<datchildren.length;j++){
                                arr[j]=newArr[j]

                            }
                            arr.concat(newArr2)

                            console.log(arr)

                        }
                        break

                    }*/

                    //数据更新
                    this.setState({
                        combinationYields: res.data.combinationYields,




                    })
                    //状态码判断
                }

            }
        ).catch(function (error) {//异常处理
            console.log(error);
        })
    }
    //组件挂载后
    componentDidMount() {
        this.getCategorys()

    }
    render() {

        return (
            <div>
                <List className="my-list">
                <Item extra={<p style={{fontSize:"1.8rem",color:"black"}}>阶段涨幅</p>}
                      style={{fontSize:"2.5rem",color:"black"}}>时间/日期</Item>
                </List>

                {(()=>{return this.state.combinationYields.map((item,index)=>{
                    return(
                        <List className="my-list">
                            <Item extra={<p style={{fontSize:"1.8rem",color:"black"}}>{item.newComIncome}</p>}
                                  style={{fontSize:"2.5rem",color:"black"}}>{item.newProTradeDate}</Item>
                        </List>
                    )
                })
                })()}


            </div>
        );
    }
}
